#include "hpy.h"
#include <bits/stdc++.h>

using namespace std;

string code() {
    string s = "ABCDE"s;
    shuffle(s.begin(), s.end());
    return s;
}

vector<string> genRing(int n, int x) {
    vector<string> s;
    for(int i = 1; i < n; i ++) s.push_back(code());
    string tar = "ABCDE"s, endt = "?????"s;
    for(string t : s) {
        for(int i = 0; i < 5; i ++)
            tar[i] = t[tar[i] - 'A'];
    }
    for(int i = 0; i < 5; i ++)
        endt[tar[i] - 'A'] = 'A' + i;
    
    for(int i = 0; i < x; i ++) {
        int a = rnd.next(5), b = rnd.next(5);
        swap(endt[a], endt[b]);
    }
    s.push_back(endt);
    return s;
}

int main(int argc, char* argv[])
{
    registerGen(argc, argv, 1);
    auto [n, m, w] = tuple{opt<int>(1), opt<int>(2), opt<int>(3)};
    vector<int> id(n), a(n), order(n);
    vector<string> s(n);
    iota(id.begin(), id.end(), 1);
    iota(order.begin(), order.end(), 0);
    shuffle(id.begin(), id.end());
    vector<vector<int> > group(m + 1);
    for(int i = 0; i < m; i ++)
        group[i].push_back(i);
    for(int i = m; i < n; i ++)
        group[rnd.next(0, m)].push_back(i);
    for(int i = 0; i < m; i ++) {
        auto v = genRing(group[i].size(), rnd.wnext(0, 2, w));
        for(int j = 0; j < group[i].size(); j ++) {
            a[group[i][j]] = group[i][(j + 1) % group[i].size()];
            s[group[i][j]] = v[j];
        }
    }

    for(auto i : group[m]) {
        a[i] = rnd.next(n);
        s[i] = code();
    }

    sort(order.begin(), order.end(), [&id](int x, int y) {return id[x] < id[y];});
    println(n);
    for(int i : order) {
        println(id[a[i]], s[i]);
    }
}
